name: detectron2-app

resources:
  accelerators: V100

setup: |
  pip install --upgrade pip

  conda activate d2

  if [ $? -eq 0 ]; then
    echo "conda env exists"
  else
    conda create -n d2 python=3.8 -y
    conda activate d2
    pip install torch torchvision
    git clone https://github.com/facebookresearch/detectron2
    cd detectron2
    pip install -e .
  fi

  cd tools
  mkdir -p datasets/coco
  cd datasets/coco

  wget http://images.cocodataset.org/zips/train2017.zip
  wget http://images.cocodataset.org/zips/val2017.zip

  unzip train2017.zip
  unzip val2017.zip

  rm train2017.zip
  rm val2017.zip

  wget http://images.cocodataset.org/annotations/annotations_trainval2017.zip
  wget http://images.cocodataset.org/annotations/stuff_annotations_trainval2017.zip

  unzip annotations_trainval2017.zip
  unzip stuff_annotations_trainval2017.zip

  rm annotations_trainval2017.zip
  rm stuff_annotations_trainval2017.zip

run: |
  conda activate d2
  
  cd detectron2/tools
  python train_net.py --config-file ../configs/COCO-InstanceSegmentation/mask_rcnn_R_50_FPN_1x.yaml --num-gpus 1 SOLVER.IMS_PER_BATCH 2 SOLVER.BASE_LR 0.0025 SOLVER.MAX_ITER 100
